# 导入fastapi包
from fastapi import FastAPI
from fastapi.responses import JSONResponse, HTMLResponse, FileResponse
from fastapi.templating import Jinja2Templates
import uvicorn

app = FastAPI()

@app.get("/user")
def user():
    # return {"msg": "get user"}
    return JSONResponse(content={"msg": "get user"},
                        status_code=222,
                        headers={"a": "b"})

# @app.get("/")
# def user():
#     # return {"msg": "get user"}
#     # 通常不会这么写, 这里就是个示例
#     html_content = """
#     <html>
#         <body> <p style="color:red"> qwq </p> </body>
#     </html>
#
#     """
#     return HTMLResponse(content=html_content)



@app.get("/avatar")
def user():
    avatar_path = "static/cute.jpg"
    # return FileResponse(avatar_path, filename="cute.jpg") # 下载图片
    return FileResponse(avatar_path)  # 直接在网页上看到图片


if __name__ == '__main__':
    uvicorn.run(app)